﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.Mobile.ContainerModel;
using System.Mobile.Mvc;

namespace MVCTestClientContainer
{
    public class ApplicationManager
    {
        private static Container container;

        static ApplicationManager()
        {
            Initialize();
        }

        private static void Initialize()
        {
            container = new Container();

            // Register Login view and controller
            container.Register<LoginForm>(c => new LoginForm());
            container.Register<LoginController>(c => new LoginController(c.Resolve<LoginForm>()))
                .InitializedBy((c, v) => v.Container = c);

            // Register Search view and controller
            container.Register<SearchForm>(c => new SearchForm());
            container.Register<SearchController>(c => new SearchController(c.Resolve<SearchForm>()))
                .InitializedBy((c, v) => v.Container = c);

            // Register Search view and controller
            container.Register<DetailForm>(c => new DetailForm());
            container.Register<DetailController>(c => new DetailController(c.Resolve<DetailForm>()))
                .InitializedBy((c, v) => v.Container = c);

            container.Register<Products>(c => new Products());


            // Set ControllerProvider
            Navigator.SetControllerProvider(new ControllerProvider(container));         
        }

        // Application entry point
        public static void Start()
        {
            LoginController loginController = container.Resolve<LoginController>();
            loginController.Initialize();           
            Application.Run(loginController.View as Form);
        }
    }
}
